package com.wynn.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    //格式化日期
    public static String getFormateDate(Date date){

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(date);

    }

    public static Date getSpecificDate(int specific){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, specific);
        Date m3 = c.getTime();
        return m3;

    }


    //获取当前月份
    public static int getCurrentMonth(){
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH) + 1;
        return month;
    }

    //获取当前年份
    public static int getCurrentYear(){
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR) ;
        return year;
    }

    //将字符串类型转化成时间类型
    public static Date stringToDate(String date){

        Double d = Double.parseDouble(date);

        Calendar base = Calendar.getInstance();
        SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //Delphi的日期类型从1899-12-30开始

        base.set(1899, 11, 30, 0, 0, 0);
        base.add(Calendar.DATE, d.intValue());
        base.add(Calendar.MILLISECOND,(int)((d % 1) * 24 * 60 * 60 * 1000));
        return base.getTime();

    }

    //将当前日期加1
    public static Date dateAdd1(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH,1);
        return calendar.getTime();
    }


}
